package com.hippomeetsskunk.savanna.types.meta;

import java.util.Collections;
import java.util.Set;

import com.hippomeetsskunk.savanna.types.person.Skill;
import com.hippomeetsskunk.savanna.types.person.Skills;


public class ResourceType extends SimObjectType {

	public final static ResourceType FIELD = new ResourceType("field", null, 36000.0, 1.0, 0.0, new Skills(Skill.FARMING, 0.01), (ResourceType[]) null);
	public static final ResourceType GRAIN = new ResourceType("grain", null, 0.0, 0.0, 0.0, new Skills(Skill.FARMING, 0.01), (ResourceType[]) null);
	public static final ResourceType SEED = new ResourceType("seed", null, 0.0, 0.0, 0.0, new Skills(Skill.FARMING, 0.01), (ResourceType[]) null);

	public static final ResourceType WHEAT = new ResourceType("wheat", GRAIN, 180.0, 10.0, 0.0);
	public static final ResourceType WHEAT_SEEDS = new ResourceType("wheat seeds", SEED, 360.0, 10.0, 0.0);

	private final static ResourceType[] values = new ResourceType[] {
		FIELD,
		GRAIN,
		SEED,
		WHEAT,
		WHEAT_SEEDS
	};
	
	private final Set<ResourceType> resourcesForImprovement;
	private final Skills skillsForImprovement;
	
	private final double lifeTime;
	private final double difficulty;
	private final double fragility;
	
	protected ResourceType(String type, ResourceType parent, double lifeTime, double difficulty, double fragility){
		this(type, parent, lifeTime, difficulty, fragility, null, (ResourceType[]) null);
	}
	
	protected ResourceType(String type, ResourceType parent, double lifeTime, double difficulty, double fragility, Skills skillsForImprovement, ResourceType ... resourcesForImprovement){
		super(type, parent);
		
		this.lifeTime = lifeTime;
		this.difficulty = difficulty;
		this.fragility = fragility;
		
		this.skillsForImprovement = skillsForImprovement;
		this.resourcesForImprovement = createSet(resourcesForImprovement);
	}

	public static ResourceType[] values() {
		return values;
	}

	public Set<ResourceType> getResourcesForImprovement() {
		if (resourcesForImprovement == null && getParent() != null) return getParent().getResourcesForImprovement();
		if (resourcesForImprovement == null) return Collections.emptySet();
		return resourcesForImprovement;
	}

	public Skills getSkillsForImprovement() {
		if (skillsForImprovement == null && getParent() != null) return getParent().getSkillsForImprovement();
		if (skillsForImprovement == null) return Skills.NO_SKILL;
		return skillsForImprovement;
	}

	public double getLifeTime() {
		return lifeTime;
	}

	public double getDifficulty() {
		return difficulty;
	}

	public double getFragility() {
		return fragility;
	}

	@Override
	protected ResourceType getParent() {
		return (ResourceType) super.getParent();
	}
}
